
    ##############################################################################################
    # R code for the Last 3 Columns (Senate) of Table 1 of Supplemental Material
    ##############################################################################################
    ### Note: This code requires the Senate Foreign Policy Votes Datasets: "All_FP_votes_S79th.txt", ..., "All_FP_votes_S111th.txt".

    library(MCMCpack)
    year.odd <- seq(from=1945, to=2009, by=2)
    T <- length(year.odd)
    # To report the share of the votes with zero discrimination parameters
    zero_discrim_percent <- rep(NA, T)
    zero_discrim_number <- rep(NA, T)
    total_vote_number <- rep(NA, T)

    ##############################################################################################   
    # Loop for 79 to 83th Senate.
    for(t in 79:83){
    Bills <- read.table(paste("All_FP_votes_S", t, "th.txt", sep=""), header=T)
    bill.label <- colnames(Bills)[-c(1:5)]
    rownames(Bills) <- paste("A", Bills$ICPSR_ID, sep="")
    Sen  <- Bills[, -c(1:5)]
    N <- nrow(Sen)
    M <- ncol(Sen) 
    row.names(Sen) <- row.names(Bills)    
    # Use different constraints: # 79-83: A3388 =  Fulbright = + ; 
    MCMC <- MCMCirt1d(Sen, theta.constraints=list(A3388="+"),
                      burnin=1000, mcmc=5000, thin=5, store.item=TRUE, store.ability=TRUE)   
    iter <- nrow(MCMC)
    gamma1.index <- N + seq(from=2, to=2*M, by=2) # gamma1 is the discrimination parameter
    gamma1.mc <- MCMC[seq(from=1, to=iter, length=iter) ,gamma1.index] 
    gamma1.CI  <- apply(gamma1.mc,  2, FUN=quantile, probs=c(0.025, 0.1, 0.5, 0.9, 0.975))
    ## Create and Save the list of Votes with zero discrimination parameters
    zero_list <- rep(NA, M)
    for(j in 1:M){ 
    if(0 < gamma1.CI[2, j] & 0 < gamma1.CI[4, j]) zero_list[j] <- 0 
    if(0 > gamma1.CI[2, j] & 0 > gamma1.CI[4, j]) zero_list[j] <- 0 
    if(0 < gamma1.CI[2, j] & 0 > gamma1.CI[4, j]) zero_list[j] <- 1 
    if(0 > gamma1.CI[2, j] & 0 < gamma1.CI[4, j]) zero_list[j] <- 1 
    }
    
    vote_list <- data.frame(zero_list, colnames(gamma1.mc))
    zero_list1 <- vote_list[zero_list==1,2]
    zero_discrim_percent[t-78] <- (sum(zero_list)/M)*100
    zero_discrim_number[t-78] <- sum(zero_list)
    total_vote_number[t-78] <- M
   
    } 


    ##############################################################################################   
    # Loop for 84th Senate.
    for(t in 84:84){
    Bills <- read.table(paste("All_FP_votes_S", t, "th.txt", sep=""), header=T)
    bill.label <- colnames(Bills)[-c(1:5)]
    rownames(Bills) <- paste("A", Bills$ICPSR_ID, sep="")
    Sen  <- Bills[, -c(1:5)]
    N <- nrow(Sen)
    M <- ncol(Sen) 
    row.names(Sen) <- row.names(Bills)    
    # Use different constraints: # 84th: HICKENLOOPER, BOURKE BLAK (R-IA) = 4382 = -
    MCMC <- MCMCirt1d(Sen, theta.constraints=list(A4382="-"),
                      burnin=1000, mcmc=5000, thin=5, store.item=TRUE, store.ability=TRUE)   
    iter <- nrow(MCMC)
    gamma1.index <- N + seq(from=2, to=2*M, by=2) # gamma1 is the discrimination parameter
    gamma1.mc <- MCMC[seq(from=1, to=iter, length=iter) ,gamma1.index] 
    gamma1.CI  <- apply(gamma1.mc,  2, FUN=quantile, probs=c(0.025, 0.1, 0.5, 0.9, 0.975))
    ## Create and Save the list of Votes with zero discrimination parameters
    zero_list <- rep(NA, M)
    for(j in 1:M){ 
    if(0 < gamma1.CI[2, j] & 0 < gamma1.CI[4, j]) zero_list[j] <- 0 
    if(0 > gamma1.CI[2, j] & 0 > gamma1.CI[4, j]) zero_list[j] <- 0 
    if(0 < gamma1.CI[2, j] & 0 > gamma1.CI[4, j]) zero_list[j] <- 1 
    if(0 > gamma1.CI[2, j] & 0 < gamma1.CI[4, j]) zero_list[j] <- 1 
    }
    
    vote_list <- data.frame(zero_list, colnames(gamma1.mc))
    zero_list1 <- vote_list[zero_list==1,2]
    zero_discrim_percent[t-78] <- (sum(zero_list)/M)*100
    zero_discrim_number[t-78] <- sum(zero_list)
    total_vote_number[t-78] <- M
   
    } 


    ##############################################################################################   
    # Loop for 85 to 94th Senate.
    for(t in 85:94){
    Bills <- read.table(paste("All_FP_votes_S", t, "th.txt", sep=""), header=T)
    bill.label <- colnames(Bills)[-c(1:5)]
    rownames(Bills) <- paste("A", Bills$ICPSR_ID, sep="")
    Sen  <- Bills[, -c(1:5)]
    N <- nrow(Sen)
    M <- ncol(Sen) 
    row.names(Sen) <- row.names(Bills)    
    # Use different constraints: # 85-94: A3658=Goldwater=+; 10808 = Kennedy = -; 9369 = Thurmond = +. Or =>  A3658="+"; A10808="-"; A9369="+"
    MCMC <- MCMCirt1d(Sen, theta.constraints=list(A3658="+", A10808="-", A9369="+"),
                      burnin=1000, mcmc=5000, thin=5, store.item=TRUE, store.ability=TRUE)   
    iter <- nrow(MCMC)
    gamma1.index <- N + seq(from=2, to=2*M, by=2) # gamma1 is the discrimination parameter
    gamma1.mc <- MCMC[seq(from=1, to=iter, length=iter) ,gamma1.index] 
    gamma1.CI  <- apply(gamma1.mc,  2, FUN=quantile, probs=c(0.025, 0.1, 0.5, 0.9, 0.975))
    ## Create and Save the list of Votes with zero discrimination parameters
    zero_list <- rep(NA, M)
    for(j in 1:M){ 
    if(0 < gamma1.CI[2, j] & 0 < gamma1.CI[4, j]) zero_list[j] <- 0 
    if(0 > gamma1.CI[2, j] & 0 > gamma1.CI[4, j]) zero_list[j] <- 0 
    if(0 < gamma1.CI[2, j] & 0 > gamma1.CI[4, j]) zero_list[j] <- 1 
    if(0 > gamma1.CI[2, j] & 0 < gamma1.CI[4, j]) zero_list[j] <- 1 
    }
    
    vote_list <- data.frame(zero_list, colnames(gamma1.mc))
    zero_list1 <- vote_list[zero_list==1,2]
    zero_discrim_percent[t-78] <- (sum(zero_list)/M)*100
    zero_discrim_number[t-78] <- sum(zero_list)
    total_vote_number[t-78] <- M
   
    } 

 
    ##############################################################################################   
    # Loop for 95 to 111th Senate.
    for(t in 95:111){
    Bills <- read.table(paste("All_FP_votes_S", t, "th.txt", sep=""), header=T)
    bill.label <- colnames(Bills)[-c(1:5)]
    rownames(Bills) <- paste("A", Bills$ICPSR_ID, sep="")
    Sen  <- Bills[, -c(1:5)]
    N <- nrow(Sen)
    M <- ncol(Sen) 
    row.names(Sen) <- row.names(Bills)    
    # Use different constraints: # 95-111 = A14105 (Helms = +);   10808 = Kennedy = -; 14920 = John Kerry = -. Or => A14105="+", A10808="-", A14920="-"
    MCMC <- MCMCirt1d(Sen, theta.constraints=list(A14105="+", A10808="-", A14920="-"),
                      burnin=1000, mcmc=5000, thin=5, store.item=TRUE, store.ability=TRUE)   
    iter <- nrow(MCMC)
    gamma1.index <- N + seq(from=2, to=2*M, by=2) # gamma1 is the discrimination parameter
    gamma1.mc <- MCMC[seq(from=1, to=iter, length=iter) ,gamma1.index] 
    gamma1.CI  <- apply(gamma1.mc,  2, FUN=quantile, probs=c(0.025, 0.1, 0.5, 0.9, 0.975))
    ## Create and Save the list of Votes with zero discrimination parameters
    zero_list <- rep(NA, M)
    for(j in 1:M){ 
    if(0 < gamma1.CI[2, j] & 0 < gamma1.CI[4, j]) zero_list[j] <- 0 
    if(0 > gamma1.CI[2, j] & 0 > gamma1.CI[4, j]) zero_list[j] <- 0 
    if(0 < gamma1.CI[2, j] & 0 > gamma1.CI[4, j]) zero_list[j] <- 1 
    if(0 > gamma1.CI[2, j] & 0 < gamma1.CI[4, j]) zero_list[j] <- 1 
    }
    
    vote_list <- data.frame(zero_list, colnames(gamma1.mc))
    zero_list1 <- vote_list[zero_list==1,2]
    zero_discrim_percent[t-78] <- (sum(zero_list)/M)*100
    zero_discrim_number[t-78] <- sum(zero_list)
    total_vote_number[t-78] <- M
   
    } 



    Votes_discrim <- data.frame(total_vote_number, zero_discrim_number, zero_discrim_percent)    
    write.csv(Votes_discrim, "Supplemental_Table1_Senate.csv")
 

